package cn.wolfcode.web.interceptor;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author L5775
 */
public class CheckLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断用户是否有登录
        //Object employee = request.getSession().getAttribute("USER_IN_SESSION");
        Employee employee = UserContext.getCurrentUser();
        if (employee != null){
            return true;
        }
        //跳转到登录页面
        response.sendRedirect("/login.html");
        return false;
    }
}
